package com.bw.module_cashier.viewmodel


import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.coroutine.CoroutineHelper
import com.bw.lib_common.entity.CashierBillEntity
import com.bw.lib_common.entity.CashierPayerEntity
import com.bw.lib_common.vm.BaseViewModel2
import com.bw.module_cashier.repo.CashierRepo
import kotlinx.coroutines.launch

/**
 * 智慧园区-05-收银台V1.1-20250507
 */
class CashierViewModel: BaseViewModel2<CashierRepo>(){
    val cashierPayerSuccess by lazy { MutableLiveData<List<CashierPayerEntity>>() }

    fun getCashier(payerId:Int){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result = mRepository.getCashier(payerId)
            if (result.code == 200){
                cashierPayerSuccess.postValue(result.data)
            } else {
                mErrorLiveData.postValue("数据异常！！")
            }
        }
    }

    val cashierDetailBillSuccess by lazy { MutableLiveData<List<CashierBillEntity>>() }

    fun getCashierDetailBill(payerId:Int){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result = mRepository.getCashierDetailBill(payerId)
            if (result.code == 200){
                cashierDetailBillSuccess.postValue(result.data)
            } else {
                mErrorLiveData.postValue("数据异常！！")
            }
        }
    }

    val addCashierBillSuccess by lazy { MutableLiveData<CashierBillEntity>() }

    fun addCashier(cashierBillEntity: CashierBillEntity){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result = mRepository.addCashier(cashierBillEntity)
            if (result.code == 200){
                addCashierBillSuccess.postValue(result.data)
            } else {
                mErrorLiveData.postValue("数据异常！！")
            }
        }
    }

    override fun createRepository(): CashierRepo = CashierRepo()
}